#include "wangge.h"
#include <QPainter>
#include <QTime>
#include <QTimer>



wangge::wangge(QWidget *parent)
    : QMainWindow(parent)
{
    resize(500,500);
    time = new QLabel(this);
    time->resize(100,100);
    time->move(0,400);
    int i=0;
    for(i=0;i<21;i++)
    {
        x[i]=10*i;
        y[i]=qrand()%200;
    }
    this->startTimer(1000);
}

wangge::~wangge()
{


}

void wangge::paintEvent(QPaintEvent *)
{

    int i=0;
    int a=20,b=20;
    QPainter painter(this);
    QPen pen(Qt::DotLine);
    //painter.setPen(pen);
    //painter.drawText(10,10,"hello word");
    painter.drawLine(0,0,0,200);
    painter.drawLine(0,200,200,200);
    painter.setPen(pen);
    for(i=0;i<10;i++)
    {
        painter.drawLine(0,a,200,a);
        a=a+20;
    }
    for(i=0;i<10;i++)
    {
        painter.drawLine(b,0,b,200);
        b=b+20;
    }
    pen.setColor(QColor(255,0,0,255));
    painter.setPen(pen);



    for(i=0;i<20;i++)
    {
        painter.drawLine(x[i],y[i],x[i+1],y[i+1]);
    }





}


void wangge::timerEvent(QTimerEvent *)
{
   int i=0;
   for(i=0;i<20;i++)
   {
       y[i]=y[i+1];
   }
   y[20]=qrand()%200;

   this->repaint();

}
